<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
  <input type="text" v-model="n1"><input type="text" v-model="n2">
  <input type="button" value="加" @click="f(1)">
  <input type="button" value="减" @click="f(2)">
  <input type="button" value="乘" @click="f(3)">
  <input type="button" value="除" @click="f(4)">
  <h1>结果:{{result}}</h1>
</div>
<script src="js/vue.js"></script>
<script>
  Vue.createApp({
    data() {
      return {
          n1:"",n2:"",result:""
      }
    },
    methods: {
      f(x) {
        /*通过this获取当前vue实例中data里面的变量*/
        // console.log(this.n1+"----"+this.n2);
        if (isNaN(this.n1)||isNaN(this.n2)){
          this.result = "输入错误!";
          return;
        }
        //判断用户点击的是什么
        switch (x) {
          case 1:
            this.result = this.n1*1+this.n2*1;
            break;
          case 2:
            this.result = this.n1-this.n2;
            break;
          case 3:
            this.result = this.n1*this.n2;
            break;
          case 4:
            this.result = this.n1/this.n2;
            break;
        }

      }
    },
  }).mount("body>div");
</script>
</body>
</html>